package constant

import (
	"github.com/lab-online/internal/shared/code"
	"github.com/lab-online/pkg/errors"
	"github.com/lab-online/pkg/gen"
	"github.com/lab-online/pkg/resp"
)

const (
	dbUnknownError   = code.DatabaseUnknownError
	dbReportNotFound = code.DatabaseReportNotFound
)

const (
	baseReqErrorCode      = resp.CodeBadRequest + domainCode
	codeReportNotFound    = baseReqErrorCode + 0
	codeNoPermissionToGet = baseReqErrorCode + 1
)

var (
	RESTErrReportNotFound    = errors.NewRESTError(400, codeReportNotFound, "未找到指定实验报告")
	RESTErrNoPermissionToGet = errors.NewRESTError(403, codeNoPermissionToGet, "无权限访问")

	DBErrUnknown        = errors.NewDBError(dbUnknownError, "report 表未定义错误")
	DBErrReportNotFound = errors.NewDBError(dbReportNotFound, "未找到指定实验报告")
)

func ErrCodeMap() gen.CodeMap {
	return gen.ParseCodeMapFromErrors(gen.ErrorMap{
		"SearchReport": {
			DBErrUnknown,
			RESTErrReportNotFound,
		},
		"GetReport": {
			DBErrUnknown,
			RESTErrReportNotFound,
			RESTErrNoPermissionToGet,
		},
	})
}
